package com.globalwave.common.convertor;

import java.sql.SQLException;
import java.sql.Timestamp;

import oracle.sql.TIMESTAMP;

import org.apache.commons.beanutils.Converter;
import org.apache.commons.beanutils.converters.SqlTimestampConverter;
import org.apache.log4j.Logger;

public class OracleDateConverter implements Converter {

	@SuppressWarnings("unchecked")
	@Override
	public Object convert(Class type, Object value) {
		Logger.getLogger(this.getClass()).debug("type>>>") ;
		if (value == null) {
	            return null;
        } else if (type == TIMESTAMP.class) {
        	final TIMESTAMP ts = (TIMESTAMP) value ;
        	try {
				return ts.timestampValue() ;
			} catch (SQLException e) {
				Logger.getLogger(this.getClass()).error("conver to timestamp Error:", e) ;
				return null ;
			}
        } else{
        	return new SqlTimestampConverter().convert(type, value);
        	//return null ;
        }
	}

}
